package com.heima.mapper;

import com.heima.pojo.*;
import com.heima.pojo.dto.NodeQueryParamDto;
import com.heima.pojo.dto.RegionQueryParamDto;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface RegionMapper {

    List<Region> getRegionList(RegionQueryParamDto areaDto);
    @Select("select name from tb_region where name = #{regionName}  and id <> #{id}")
    String selectRegionByName(String regionName,Long id);
    @Select("select name from tb_region where name = #{regionName}")
    String selectRegionByNameReturn1(String regionName);
    @Insert("INSERT INTO tb_region set name = #{regionName}, remark = #{remark}")
    void addRegion(Region2 region);

    @Select("select count(*) from tb_vending_machine where region_id = #{regionId};")
    int selectRegionVMCountByRegionId(long regionId);

    @Update("update tb_region set name = #{regionName}, remark = #{remark} where id = #{id}")
    void updateRegion(Region2 region2);


    List<Node> getNodeList(NodeQueryParamDto nodeDto);

    @Select("select id from tb_region where id = #{id}")
    Long selectRegionByName2(String id);

    @Select("select * from tb_region where id = #{regionId}")
    Region selectRegionByRegionId2(Long regionId);

    @Select("select tb.* from tb_business tb left join tb_node tn on tb.id = tn.business_id where tn.id = #{id};")
    Business selectBusinessTypefromNode(Integer id);

    @Delete("delete from tb_region where id = #{regionId}")
    void deleteRegion(String regionId);

    @Select("select count(*) from tb_vending_machine where region_id = #{regionId}")
    Long selectVMCount(Long regionId);
}
